package com.xiaocg.demowebflux.controller;

import com.xiaocg.demowebflux.entity.Person;
import com.xiaocg.demowebflux.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class PersonController {

    @Autowired
    private PersonService personService;

    @GetMapping("/user/{id}")
    public Mono<Person> getById(@PathVariable Long id){
        return personService.getById(id);
    }

    @GetMapping("/list")
    public Flux<Person> list(){
        return personService.listAll();
    }

    @PostMapping("/user")
    public Mono<Void> add(@RequestBody Person person){
        return personService.add(Mono.just(person));
    }
}
